package com.gpnu.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gpnu.crm.domain.CustomerTraceHistory;
import com.gpnu.crm.mapper.CustomerTraceHistoryMapper;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.ICustomerTraceHistoryService;
import com.gpnu.crm.util.UserContext;

//员工对象在业务层实现，需要交给Spring来创建对象
@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService {

	@Autowired
	private CustomerTraceHistoryMapper customerTraceHistoryMapper;

	public CustomerTraceHistoryServiceImpl() {
	}

	public PageInfo<CustomerTraceHistory> query(QueryObject qo) {
		PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderby());
		List<CustomerTraceHistory> list = customerTraceHistoryMapper.selectAll(qo);
		return new PageInfo(list);
	}

	  public void saveOrUpdate(CustomerTraceHistory entity) {
		    entity.setInputTime(new Date());
		    if (entity.getId() == null) {
		      
		      entity.setInputUser(UserContext.getCurrentUser());
		      this.customerTraceHistoryMapper.insert(entity);
		    } else {
		      this.customerTraceHistoryMapper.updateByPrimaryKey(entity);
		    } 
		  }

}
